﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CustomControls.MessageBox
{
    /// <summary>
    /// MessageBoxWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MessageBoxWindow : MessageBaseWindow
    {
        public MessageBoxWindow(string content)
        {
            InitializeComponent();
            MessageInfo.Text = content;
            MessageBoxResult = System.Windows.MessageBoxResult.None;
        }

        #region 属性

        /// <summary>
        /// 消息框按钮返回值
        /// </summary>
        public MessageBoxResult MessageBoxResult
        {
            get;
            set;
        }

        /// <summary>
        /// 获取或设置窗口的标题
        /// </summary>
        public new string Title
        {
            get { return base.Title; }
            set
            {
                base.Title = value;
                winContainer.Title = value;
            }
        }

        #endregion

        #region 事件方法

        void MessageInfo_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (MessageInfo.Text.Length > 100)
            {
                double textheight = (double)MessageInfo.Text.Length / 25 * 20;
                MessageInfo.Height = textheight < 50 ? 50 : textheight;
                MessageInfo.Width = 300;
            }
            else
            {
                MessageInfo.Width = 200;
                MessageInfo.Height = 50;
            }
        }

        private void btn_confirm_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult = MessageBoxResult.OK;
            this.Close();
        }

        private void btn_Yes_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult = MessageBoxResult.Yes;
            this.Close();
        }

        private void btn_No_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult = MessageBoxResult.No;
            this.Close();
        }

        private void btn_cancel_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult = MessageBoxResult.Cancel;
            this.Close();
        }

        #endregion
    }
}
